package schema

import (
	"entgo.io/ent"
	"entgo.io/ent/schema/edge"
	"entgo.io/ent/schema/field"
	"time"
)

// Wish holds the schema definition for the Wish entity.
type Wish struct {
	ent.Schema
}

// Fields of the Wish.
func (Wish) Fields() []ent.Field {
	return []ent.Field{
		field.Text("content").
			NotEmpty().
			Comment("想做的事"),
		field.Bool("is_completed").
			Default(false).
			Comment("是否完成"),
		field.Time("completed_at").
			Optional().
			Nillable().
			Comment("完成时间"),
		field.Int64("creator_id").
			Comment("创建者ID"),
		field.Time("created_at").
			Default(time.Now).
			Immutable().
			Comment("创建时间"),
		field.Time("updated_at").
			Default(time.Now).
			UpdateDefault(time.Now).
			Comment("更新时间"),
	}
}

// Edges of the Wish.
func (Wish) Edges() []ent.Edge {
	return []ent.Edge{
		edge.From("creator", User.Type).
			Ref("wishes").
			Field("creator_id").
			Unique().
			Required(),
	}
}
